/**
 *  MicroEmulator
 *  Copyright (C) 2006-2007 Bartek Teodorczyk <barteo@barteo.net>
 *  Copyright (C) 2006-2007 Vlad Skarzhevskyy
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  @version $Id: AppletProducer.java 940 2009-03-16 09:30:02
 */


package org.microemu.util;

/**
 * BlueWhaleSystems fix: Michael Busheikin - 16 March 2009
 *
 * Custom string utilities. 
 */
public class StringUtils
{

	/**
	 * Returns a new string containing part of an original string,
	 * from the beginning index to the end index. 
	 * @param aOriginal The original string of which to take a substring.
	 * @param aBeginIndex The start index of the substring.
	 * @param aEndIndex The end index of the substring.
	 * @return The substring. If the beginning index 
	 * is positive and too large, returns an empty string. Otherwise, if the 
	 * beginning index is negative treats it as the first index, and if
	 * the ending index is too large treats it as the last index in the string. 
	 */
    public static String substring(String aOriginal, int aBeginIndex, int aEndIndex)
    {
        int len = aOriginal.length();
        if(aBeginIndex >= len)
            return "";
        if(aEndIndex > len)
            return aOriginal.substring(aBeginIndex);
        else
            return aOriginal.substring(aBeginIndex, aEndIndex);
    }

    /**
     * Returns a new string containing part of an original string,
	 * from the beginning index to the end of the string. 
	 * @param aOriginal The original string of which to take a substring.
	 * @param aBeginIndex The start index of the substring.
     * @return The substring. If the beginning index is too large, returns 
     *   an empty string. 
     */
    public static String substring(String aOriginal, int aBeginIndex)
    {
        int len = aOriginal.length();
        if(aBeginIndex >= len)
            return "";
        else
            return aOriginal.substring(aBeginIndex);
    }
}